(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.role.viewController', viewController);
	viewController.$inject = [ '$scope', 'Constants', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'roleService' ];
	function viewController($scope, Constants, layoutConfig, validatorConfig, gridService, authService, roleService) {
		var ctrl = this, roleInfo = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.role={};
		ctrl.init = function() {
			var params = {
					roleCode : roleInfo.roleCode
			};
			
			ctrl.roleRightGridOptions = gridService.createInnerGridOptions($scope, ctrl.layoutConfig.formConfigs.roleRight.tableConfigs.table, rowSelectionChanged);
			ctrl.roleRightGridOptions.data = 'vm.role.roleRights';
			ctrl.roleRightGridOptions.enableRowHeaderSelection = false;
			function rowSelectionChanged(eventRow, selectedRows) {
				ctrl.selectedDTParmList = selectedRows;
			}
			return authService.view(params).then(function(response){
				ctrl.role = response.data || roleInfo;
				ctrl.role.dataStatus = ctrl.role.dataStatus;
				ctrl.role.roleRights = ctrl.role.roleRights || [];
				angular.forEach(ctrl.role.roleRights, function (con, key){
					if (con.dataStatus == 'V' || con.dataStatus == null) {
						con.dataStatus = 'V';
					} else {
						con.dataStatus = ctrl.role.dataStatus;
					}
				});
			},angular.noop());
		};
		
	}
})(angular);